<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>规则信息表修改</title>
<link href="../../static/plugin/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
<link href="../../static/plugin/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
<link href="../../static/css/esaas-easyui-edit.css" rel="stylesheet" type="text/css"/>
<script src="../../static/plugin/easyui/jquery.min.js" type="text/javascript"></script>
<script src="../../static/plugin/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../static/plugin/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
<script src="../../ffres/dict/all.js" type="text/javascript"></script>
<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<body class="easyui-layout" scroll="no">
	<form id="ff" method="post">
		<div class="esaas-info-title">规则信息表信息</div>
		<table class="esaas-info-edit-table">
			<tr>
				<td width="15%" align="right">规则id：</td>
				<td width="35%"><input class="easyui-textbox" type="text" readOnly
					name="ruleId" data-options="required:true"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">规则名称：</td>
				<td width="35%"><input class="easyui-textbox" type="text" 
					name="ruleName" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则描述：</td>
				<td width="35%"><input class="easyui-textbox" type="text" 
					name="ruleDesc" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">规则类型：</td>
				<td width="35%"><select class="easyui-combobox"
						id="ruleType" name="ruleType"
						style="width: 100%; height: 25px;"
						data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:RULE_TYPE">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">规则适用类型：</td>
				<td width="35%"><select class="easyui-combobox"
						id="adapterType" name="adapterType"
						style="width: 100%; height: 25px;"
						data-options="required:true,editable:false,valueField:'enname',textField:'cnname',data:ADAPTER_TYPE">
				</select></td>
			</tr>
			<tr>
				<td width="15%" align="right">创建用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="createUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">创建日期：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="createTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
			<tr>
				<td width="15%" align="right">最后修改时间：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="updateTime" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
				<td width="15%" align="right">最新变更用户：</td>
				<td width="35%"><input class="easyui-textbox" type="text"  readOnly
					name="updateUser" data-options="required:false"
					style="width: 100%; height: 25px;"></input></td>
			</tr>
		</table>
	</form>
	<div style="text-align: center; padding: 15px">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			onclick="submitForm()">&nbsp;保&nbsp;存&nbsp;</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			onclick="closeForm()">&nbsp;关&nbsp;闭&nbsp;</a>
	</div>

	<table id="paramdg" class="easyui-datagrid" title="规则参数配置" style="height:auto"
		   rownumbers="true"
		   data-options="
                iconCls: 'icon-edit',
                singleSelect: true,
                toolbar: '#paramtb',
                onClickCell: onClickCell,
                onEndEdit: onEndEdit
            ">
		<thead>
		<tr>
			<th data-options="field:'paramId',resizable:true,width:250,editor:{type:'textbox',options:{required:true}}" >规则参数id</th>
			<th data-options="field:'paramDesc',resizable:true,width:250,editor:{type:'textbox',options:{required:true}}" >参数描述</th>
			<th data-options="field:'paramConf',resizable:true,width:250,editor:{type:'textbox',options:{required:true}}" >参数配置</th>
			<th data-options="field:'confDesc',resizable:true,width:250,editor:{type:'textbox',options:{required:true}}" >配置描述</th>
		</tr>
		</thead>
	</table>
	<div id="paramtb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" data-options="plain:true" onclick="appendParam()">新增</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" data-options="plain:true" onclick="removeitParam()">删除</a>
	</div>
	<script>
        var editIndex = undefined;
        function endEditing(){
            if (editIndex == undefined){return true}
            if ($('#paramdg').datagrid('validateRow', editIndex)){
                $('#paramdg').datagrid('endEdit', editIndex);
                editIndex = undefined;
                return true;
            } else {
                return false;
            }
        }
        function onClickCell(index, field){
            if (editIndex != index){
                if (endEditing()){
                    $('#paramdg').datagrid('selectRow', index)
                        .datagrid('beginEdit', index);
                    var ed = $('#paramdg').datagrid('getEditor', {index:index,field:field});
                    if (ed){
                        ($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
                    }
                    editIndex = index;
                } else {
                    setTimeout(function(){
                        $('#paramdg').datagrid('selectRow', editIndex);
                    },0);
                }
            }
        }
        function onEndEdit(index, row){

        }
        function appendParam(){
            if (endEditing()){
                $('#paramdg').datagrid('appendRow',{status:'P'});
                editIndex = $('#paramdg').datagrid('getRows').length-1;
                $('#paramdg').datagrid('selectRow', editIndex)
                    .datagrid('beginEdit', editIndex);
            }
        }
        function removeitParam(){
            if (editIndex == undefined){return}
            $('#paramdg').datagrid('cancelEdit', editIndex)
                .datagrid('deleteRow', editIndex);
            editIndex = undefined;
        }
		$(function() {
			var ruleId = $.getUrlParam('ruleId');
			$.restfulPostJson('../../api/s/rule/info/all', {ruleId:ruleId},function(data){
					$('#ff').form('load', {
						ruleId : data.rows.ruleId,
						ruleName : data.rows.ruleName,
						ruleDesc : data.rows.ruleDesc,
						ruleType : data.rows.ruleType,
                        adapterType : data.rows.adapterType,
						createUser : data.rows.createUser,
						createTime : data.rows.createTime,
						updateTime : data.rows.updateTime,
						updateUser : data.rows.updateUser
					});
					$('#paramdg').datagrid({data: data.rows.params})
			});
		});
	
		function submitForm() {
            if (!endEditing()) {
                return;
            }
			if (!$('#ff').form('validate'))
				return;
			var jsonData = $("#ff").serializeJson();
            var params = $('#paramdg').datagrid('getRows');
            jsonData.params = params;
            $.restfulPut('../../api/s/rule/info/all', jsonData, function(data) {
                window.parent.reloadList();
            });
		};
		
		function closeForm(){
			window.parent.JLEUtil.closewin();
		}
	</script>
</body>
</html>
